const app = getApp();

// pages/mine/set/set.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    chose: 1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    var that = this;
    wx.showLoading({
      title: '加载中...',
    });

    if (app.globalData.userData.openOId){
      wx.request({
        url: app.globalData.phpUrl + 'user/api',
        method: "POST",
        header: { 'content-type': 'application/json' },
        data: { api_name: 'my_question', openid: app.globalData.userData.openOId, is_publish: 1 },
        success: function (data) {
          that.setData({
            list: data.data.data.list,
          });
          wx.hideLoading()
        }
      })
    }else{
      app.globalData.loadIndex = function (opId) {
        wx.request({
          url: app.globalData.phpUrl + 'user/api',
          method: "POST",
          header: { 'content-type': 'application/json' },
          data: { api_name: 'my_question', openid: opId, is_publish: 1 },
          success: function (data) {
            that.setData({
              list: data.data.data.list,
            });
            wx.hideLoading()
          }
        })
      }
    }
  },

  radioChange: function (e) {
    var that = this;
    this.setData({
      chose: e.detail.value
    });

    var is_publish = e.detail.value == 1 ? 1 : 0
    wx.showLoading({
      title: '请稍候 ...',
    });
    wx.request({
      url: app.globalData.phpUrl + 'user/api',
      method: "POST",
      header: { 'content-type': 'application/json' },
      data: { api_name: 'my_question', openid: app.globalData.userData.openOId, is_publish: is_publish },
      success: function (data) {
        that.setData({
          list: data.data.data.list,
        });
        wx.hideLoading()
      }
    })
  },

  questionData:function(e){
      wx.navigateTo({
        url: '../dataReport/dataReport?questionnaire_id=' + Number(e.currentTarget.dataset.quid),
      })
  },

  editQuestion:function(e){
    app.globalData.setId = e.currentTarget.dataset.id
    wx.switchTab({
      url: '../../setTopic/setTopic?source=set',
    });
  }
})